#include "result.h"

#include <algorithm>
Result::Result(std::shared_ptr<Task> task, bool isValid)
    : task_(task), isValid_(isValid) {
    task->setResult(this);
}

Any Result::get() {
    if (!isValid_) {
        return "";
    }

    sema_.wait();
    return std::move(any_);
}

void Result::setVal(Any any) {
    this->any_ = std::move(any);
    sema_.post();
}
